<?php
class Current_holding_model extends MY_Model{

    function __construct()
    {
        parent::__construct();
        $this->_table        =    'current_holdings';   //ten table trong db
        $this->primary_key    =    'id';     //khoa chinh
    }
    
    function return_value_by_year($year = null)
    {
    	$row    =    $this->db->select()->from($this->_table)->where('customer_id',$_SESSION["customer"]["id"])->get()->row_array();//$this->current_holding_model->get_by('customer_id',$_SESSION["customer"]["id"]);
    	$y=0;
    	$n	=	$year-date('Y');
    	if($row){
    		$y_sb	=	$row['SB']*pow((1+($row['SBR']/100)),$n);
			$y_sb	=	round(floatval($y_sb));
			
			$y_ss	=	$row['SS']*pow((1+($row['SSR']/100)),$n);
			$y_ss	=	round(floatval($y_ss));
			
			$y_us	=	$row['US']*pow((1+($row['USR']/100)),$n);
			$y_us	=	round(floatval($y_us));
			
			$y_b	=	$row['B']*pow((1+($row['BR']/100)),$n);
			$y_b	=	round(floatval($y_b));
			
			$y_fd	=	$row['FD']*pow((1+($row['FDR']/100)),$n);
			$y_fd	=	round(floatval($y_fd));
			
			$y_ip	=	$row['IP']*pow((1+($row['IPR']/100)),$n);
			$y_ip	=	round(floatval($y_ip));
			
			$y_cpf	=	$row['CPF']*pow((1+($row['CPFR']/100)),$n);
			$y_cpf	=	round(floatval($y_cpf));
			
			$y=$y_sb+$y_ss+$y_us+$y_b+$y_fd+$y_ip+$y_cpf;
    	}
    	return $y;
    }
}